package at.codebase.web.servlets.admin;

import java.util.ArrayList;

import at.codebase.core.Settings;
import at.codebase.db.dao.EUserDao;
import at.codebase.db.entities.EUser;
import at.codebase.web.util.LocalRequest.RequestInformation;
import at.codebase.web.util.servlet.SecureServlet;

/**
 * @author Daniel Marth <danielmarth@gmx.at>
 */
public class CreateDummyUsers extends SecureServlet {

	@Override
	protected void initSecurityLevels(ArrayList<UserLevel> secLevels) {
		secLevels.add(UserLevel.ADMIN);
	}

	@Override
	protected void processRequestSecurityLevel(RequestInformation requestInfo,
			UserLevel level, RequestType requestType) {
		// Generate Admin Account
		for (String adminMail : Settings.ADMIN_ACCOUNT_MAILS) {
			if (!EUserDao.duplicateUsername(adminMail.substring(0,
					adminMail.indexOf("@")))) {
				EUser user = EUser.createExampleUser(
						adminMail.substring(0, adminMail.indexOf("@")),
						adminMail, "example.com", true);
				EUserDao.saveUser(user);
			}
		}
	}

}
